package com.tudouji.project.document.controller;

import java.util.List;

import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.framework.web.page.TableDataInfo;
import com.tudouji.project.document.domain.DocumentDefine;
import com.tudouji.project.document.service.IDocumentDefineService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 单证/协议定义Controller
 *
 * @author coal
 * @date 2021-12-06
 */
@RestController
@RequestMapping("/document/define")
public class DocumentDefineController extends BaseController {
    @Autowired
    private IDocumentDefineService documentDefineService;

    /**
     * 查询单证/协议定义列表
     */
    @PreAuthorize("@ss.hasPermi('document:define:list')")
    @GetMapping("/list")
    public TableDataInfo list(DocumentDefine documentDefine) {
        startPage();
        List<DocumentDefine> list = documentDefineService.selectDocumentDefineList(documentDefine);
        return getDataTable(list);
    }

    /**
     * 导出单证/协议定义列表
     */
    @PreAuthorize("@ss.hasPermi('document:define:export')")
    @Log(title = "单证/协议定义", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DocumentDefine documentDefine) {
        List<DocumentDefine> list = documentDefineService.selectDocumentDefineList(documentDefine);
        ExcelUtil<DocumentDefine> util = new ExcelUtil<DocumentDefine>(DocumentDefine.class);
        return util.exportExcel(list, "单证/协议定义数据");
    }

    /**
     * 获取单证/协议定义详细信息
     */
    @PreAuthorize("@ss.hasPermi('document:define:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(documentDefineService.selectDocumentDefineById(id));
    }

    /**
     * 新增单证/协议定义
     */
    @PreAuthorize("@ss.hasPermi('document:define:add')")
    @Log(title = "单证/协议定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DocumentDefine documentDefine) {
        return toAjax(documentDefineService.insertDocumentDefine(documentDefine));
    }

    /**
     * 修改单证/协议定义
     */
    @PreAuthorize("@ss.hasPermi('document:define:edit')")
    @Log(title = "单证/协议定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DocumentDefine documentDefine) {
        return toAjax(documentDefineService.updateDocumentDefine(documentDefine));
    }

    /**
     * 删除单证/协议定义
     */
    @PreAuthorize("@ss.hasPermi('document:define:remove')")
    @Log(title = "单证/协议定义", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(documentDefineService.deleteDocumentDefineByIds(ids));
    }
}
